{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Network DEA讀檔函式示範\n",
    "在此示範如何使用csv2dict_for_network_dea()來讀取要被衡量的資料，以利後續放入Network DEA主程式時使用，並顯示它們最終形成的資料形式。<br>\n",
    "\n",
    "※示範程式碼及csv資料存放於[這裡](https://github.com/wurmen/DEA/tree/master/Functions/network_data%26code)，可自行下載測試。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import network_function  #導入存放csv2dict_for_network_dea()的py檔(在此名為network_function)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "DMU, X, Z_input, p_n=network_function.csv2dict_for_network_dea('network_example1_inputdata.csv', v1_range=[2,3], v2_range=[4,5], p_n=3)\n",
    "DMU, Y, Z_output, p_n=network_function.csv2dict_for_network_dea('network_example1_outputdata.csv', v1_range=[2,2], v2_range=[3,4], p_n=3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['A', 'B', 'C', 'D', 'E']\n"
     ]
    }
   ],
   "source": [
    "print(DMU) # print DMU list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n"
     ]
    }
   ],
   "source": [
    "print(p_n) # print number of processes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'A': [[11.0, 14.0], [3.0, 5.0], [4.0, 3.0], [4.0, 6.0]], 'C': [[11.0, 14.0], [3.0, 4.0], [5.0, 3.0], [3.0, 7.0]], 'B': [[7.0, 7.0], [2.0, 3.0], [2.0, 1.0], [3.0, 3.0]], 'E': [[14.0, 15.0], [5.0, 6.0], [5.0, 4.0], [4.0, 5.0]], 'D': [[14.0, 14.0], [4.0, 6.0], [5.0, 5.0], [5.0, 3.0]]}\n"
     ]
    }
   ],
   "source": [
    "print(X) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'A': [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [2.0, 1.0]], 'C': [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 1.0]], 'B': [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 1.0]], 'E': [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 2.0]], 'D': [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 1.0]]}\n"
     ]
    }
   ],
   "source": [
    "print(Z_input)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'A': [[1.0], [0.0], [0.0], [1.0]], 'C': [[2.0], [0.0], [0.0], [2.0]], 'B': [[1.0], [0.0], [0.0], [1.0]], 'E': [[3.0], [0.0], [0.0], [3.0]], 'D': [[1.0], [0.0], [0.0], [1.0]]}\n"
     ]
    }
   ],
   "source": [
    "print(Y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'A': [[2.0, 2.0], [4.0, 0.0], [0.0, 3.0], [0.0, 0.0]], 'C': [[1.0, 1.0], [2.0, 0.0], [0.0, 2.0], [0.0, 0.0]], 'B': [[1.0, 1.0], [2.0, 0.0], [0.0, 2.0], [0.0, 0.0]], 'E': [[3.0, 2.0], [4.0, 0.0], [0.0, 4.0], [0.0, 0.0]], 'D': [[2.0, 3.0], [3.0, 0.0], [0.0, 4.0], [0.0, 0.0]]}\n"
     ]
    }
   ],
   "source": [
    "print(Z_output)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "DMU, X, Z_input, p_n=network_function.csv2dict_for_network_dea('network_example2_inputdata.csv', v1_range=[2,3], v2_range=[4,5], p_n=2)\n",
    "DMU, Y, Z_output, p_n=network_function.csv2dict_for_network_dea('network_example2_outputdata.csv', v1_range=[2,3], v2_range=[4,5], p_n=2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Taiwan Fire', 'Chung Kuo', 'Tai Ping', 'China Mariners', 'Fubon', 'Zurich', 'Taian', 'Ming Tai', 'Central', 'the first', 'Kuo Hua', 'Union', 'Shing kong', 'South China', 'CathayCentury', 'Allianz President', 'Newa', 'AIU', 'North America', 'Federal', 'Royal&Sunalliance', 'Asia', 'AXA', 'Mitsui Sumitomo']\n"
     ]
    }
   ],
   "source": [
    "print(DMU)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n"
     ]
    }
   ],
   "source": [
    "print(p_n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'Royal&Sunalliance': [[26224.0, 84171.0], [26224.0, 0.0], [0.0, 84171.0]], 'AIU': [[547997.0, 757515.0], [547997.0, 0.0], [0.0, 757515.0]], 'Asia': [[10502.0, 15993.0], [10502.0, 0.0], [0.0, 15993.0]], 'AXA': [[28408.0, 54693.0], [28408.0, 0.0], [0.0, 54693.0]], 'Fubon': [[3531614.0, 6699063.0], [3531614.0, 0.0], [0.0, 6699063.0]], 'Allianz President': [[415071.0, 1211716.0], [415071.0, 0.0], [0.0, 1211716.0]], 'Taiwan Fire': [[673512.0, 1178744.0], [673512.0, 0.0], [0.0, 1178744.0]], 'Chung Kuo': [[1352755.0, 1381822.0], [1352755.0, 0.0], [0.0, 1381822.0]], 'Newa': [[1085019.0, 1453797.0], [1085019.0, 0.0], [0.0, 1453797.0]], 'Ming Tai': [[1873530.0, 3789001.0], [1873530.0, 0.0], [0.0, 3789001.0]], 'Union': [[650952.0, 2592790.0], [650952.0, 0.0], [0.0, 2592790.0]], 'CathayCentury': [[651063.0, 2184944.0], [651063.0, 0.0], [0.0, 2184944.0]], 'China Mariners': [[594259.0, 601320.0], [594259.0, 0.0], [0.0, 1177494.0]], 'Federal': [[53518.0, 145442.0], [53518.0, 0.0], [0.0, 145442.0]], 'Central': [[950432.0, 1567746.0], [950432.0, 0.0], [0.0, 1567746.0]], 'Shing kong': [[1368802.0, 2609941.0], [1368802.0, 0.0], [0.0, 2609941.0]], 'Tai Ping': [[592790.0, 1177494.0], [592790.0, 0.0], [0.0, 1177494.0]], 'Mitsui Sumitomo': [[235094.0, 163297.0], [235094.0, 0.0], [0.0, 163297.0]], 'South China': [[988888.0, 1396002.0], [988888.0, 0.0], [0.0, 1396002.0]], 'North America': [[182338.0, 159422.0], [182338.0, 0.0], [0.0, 159422.0]], 'Kuo Hua': [[672414.0, 1962448.0], [672414.0, 0.0], [0.0, 1962448.0]], 'the first': [[1298470.0, 1303249.0], [1298470.0, 0.0], [0.0, 1303249.0]], 'Zurich': [[668363.0, 2627707.0], [668363.0, 0.0], [0.0, 2627707.0]], 'Taian': [[1443100.0, 1942833.0], [1443100.0, 0.0], [0.0, 1942833.0]]}\n"
     ]
    }
   ],
   "source": [
    "print(X)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'Royal&Sunalliance': [[0.0, 0.0], [0.0, 0.0], [225888.0, 40542.0]], 'AIU': [[0.0, 0.0], [0.0, 0.0], [3631484.0, 995620.0]], 'Asia': [[0.0, 0.0], [0.0, 0.0], [52063.0, 14574.0]], 'AXA': [[0.0, 0.0], [0.0, 0.0], [245910.0, 49864.0]], 'Fubon': [[0.0, 0.0], [0.0, 0.0], [37392862.0, 1753794.0]], 'Allianz President': [[0.0, 0.0], [0.0, 0.0], [5606013.0, 402881.0]], 'Taiwan Fire': [[0.0, 0.0], [0.0, 0.0], [7451757.0, 856735.0]], 'Chung Kuo': [[0.0, 0.0], [0.0, 0.0], [10020274.0, 1812894.0]], 'Newa': [[0.0, 0.0], [0.0, 0.0], [7695461.0, 342489.0]], 'Ming Tai': [[0.0, 0.0], [0.0, 0.0], [17267266.0, 1134600.0]], 'Union': [[0.0, 0.0], [0.0, 0.0], [9434406.0, 1118489.0]], 'CathayCentury': [[0.0, 0.0], [0.0, 0.0], [10422297.0, 749893.0]], 'China Mariners': [[0.0, 0.0], [0.0, 0.0], [3174851.0, 371863.0]], 'Federal': [[0.0, 0.0], [0.0, 0.0], [316829.0, 131920.0]], 'Central': [[0.0, 0.0], [0.0, 0.0], [11473162.0, 546337.0]], 'Shing kong': [[0.0, 0.0], [0.0, 0.0], [13921464.0, 811343.0]], 'Tai Ping': [[0.0, 0.0], [0.0, 0.0], [4776548.0, 560244.0]], 'Mitsui Sumitomo': [[0.0, 0.0], [0.0, 0.0], [476419.0, 644816.0]], 'South China': [[0.0, 0.0], [0.0, 0.0], [7396396.0, 465509.0]], 'North America': [[0.0, 0.0], [0.0, 0.0], [1141950.0, 483291.0]], 'Kuo Hua': [[0.0, 0.0], [0.0, 0.0], [7222378.0, 643178.0]], 'the first': [[0.0, 0.0], [0.0, 0.0], [8210389.0, 504528.0]], 'Zurich': [[0.0, 0.0], [0.0, 0.0], [9747908.0, 952326.0]], 'Taian': [[0.0, 0.0], [0.0, 0.0], [10685457.0, 643412.0]]}\n"
     ]
    }
   ],
   "source": [
    "print(Z_input)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'Royal&Sunalliance': [[51950.0, 6491.0], [51950.0, 0.0], [0.0, 6491.0]], 'AIU': [[692731.0, 163927.0], [692731.0, 0.0], [0.0, 163927.0]], 'Asia': [[82141.0, 4181.0], [82141.0, 0.0], [0.0, 4181.0]], 'AXA': [[0.1, 18980.0], [0.1, 0.0], [0.0, 18980.0]], 'Fubon': [[7851229.0, 3925272.0], [7851229.0, 0.0], [0.0, 3925272.0]], 'Allianz President': [[854054.0, 197947.0], [854054.0, 0.0], [0.0, 197947.0]], 'Taiwan Fire': [[984143.0, 681687.0], [984143.0, 0.0], [0.0, 681687.0]], 'Chung Kuo': [[1228502.0, 834754.0], [1228502.0, 0.0], [0.0, 834754.0]], 'Newa': [[3144484.0, 371984.0], [3144484.0, 0.0], [0.0, 371984.0]], 'Ming Tai': [[3899530.0, 622868.0], [3899530.0, 0.0], [0.0, 622868.0]], 'Union': [[1574191.0, 909295.0], [1574191.0, 0.0], [0.0, 909295.0]], 'CathayCentury': [[3355197.0, 555482.0], [3355197.0, 0.0], [0.0, 555482.0]], 'China Mariners': [[248709.0, 177331.0], [248709.0, 0.0], [0.0, 177331.0]], 'Federal': [[355624.0, 26537.0], [355624.0, 0.0], [0.0, 26537.0]], 'Central': [[1043778.0, 264098.0], [1043778.0, 0.0], [0.0, 264098.0]], 'Shing kong': [[3609236.0, 223047.0], [3609236.0, 0.0], [0.0, 223047.0]], 'Tai Ping': [[293613.0, 658428.0], [293613.0, 0.0], [0.0, 658428.0]], 'Mitsui Sumitomo': [[142370.0, 16976.0], [142370.0, 0.0], [0.0, 16976.0]], 'South China': [[1401200.0, 332283.0], [1401200.0, 0.0], [0.0, 332283.0]], 'North America': [[519121.0, 46857.0], [519121.0, 0.0], [0.0, 46857.0]], 'Kuo Hua': [[1486014.0, 18259.0], [1486014.0, 0.0], [0.0, 18259.0]], 'the first': [[1697941.0, 554806.0], [1697941.0, 0.0], [0.0, 554806.0]], 'Zurich': [[1713598.0, 415058.0], [1713598.0, 0.0], [0.0, 415058.0]], 'Taian': [[2239593.0, 439039.0], [2239593.0, 0.0], [0.0, 439039.0]]}\n"
     ]
    }
   ],
   "source": [
    "print(Y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'Royal&Sunalliance': [[0.0, 0.0], [225888.0, 40542.0], [0.0, 0.0]], 'AIU': [[0.0, 0.0], [3631484.0, 995620.0], [0.0, 0.0]], 'Asia': [[0.0, 0.0], [52063.0, 14574.0], [0.0, 0.0]], 'AXA': [[0.0, 0.0], [245910.0, 49864.0], [0.0, 0.0]], 'Fubon': [[0.0, 0.0], [37392862.0, 1753794.0], [0.0, 0.0]], 'Allianz President': [[0.0, 0.0], [5606013.0, 402881.0], [0.0, 0.0]], 'Taiwan Fire': [[0.0, 0.0], [7451757.0, 856735.0], [0.0, 0.0]], 'Chung Kuo': [[0.0, 0.0], [10020274.0, 1812894.0], [0.0, 0.0]], 'Newa': [[0.0, 0.0], [7695461.0, 342489.0], [0.0, 0.0]], 'Ming Tai': [[0.0, 0.0], [17267266.0, 1134600.0], [0.0, 0.0]], 'Union': [[0.0, 0.0], [9434406.0, 1118489.0], [0.0, 0.0]], 'CathayCentury': [[0.0, 0.0], [10422297.0, 749893.0], [0.0, 0.0]], 'China Mariners': [[0.0, 0.0], [3174851.0, 371863.0], [0.0, 0.0]], 'Federal': [[0.0, 0.0], [316829.0, 131920.0], [0.0, 0.0]], 'Central': [[0.0, 0.0], [11473162.0, 546337.0], [0.0, 0.0]], 'Shing kong': [[0.0, 0.0], [13921464.0, 811343.0], [0.0, 0.0]], 'Tai Ping': [[0.0, 0.0], [4776548.0, 560244.0], [0.0, 0.0]], 'Mitsui Sumitomo': [[0.0, 0.0], [476419.0, 644816.0], [0.0, 0.0]], 'South China': [[0.0, 0.0], [7396396.0, 465509.0], [0.0, 0.0]], 'North America': [[0.0, 0.0], [1141950.0, 483291.0], [0.0, 0.0]], 'Kuo Hua': [[0.0, 0.0], [7222378.0, 643178.0], [0.0, 0.0]], 'the first': [[0.0, 0.0], [8210389.0, 504528.0], [0.0, 0.0]], 'Zurich': [[0.0, 0.0], [9747908.0, 952326.0], [0.0, 0.0]], 'Taian': [[0.0, 0.0], [10685457.0, 643412.0], [0.0, 0.0]]}\n"
     ]
    }
   ],
   "source": [
    "print(Z_output)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
